From: Liangent Date: Sun, 26 May 2013 07:37:42 +0000 (+0000) Subject: Never prefix table names with $wgSharedDB when used in foreign DB X-Git-Tag: 1.31.0-rc.0~19013^2 X-Git-Url: http://git.cyclocoop.org/%7D%7Cconcat%7B?a=commitdiff_plain;h=af154bea2bd58112674c4dd71acc396152ab3653;p=lhc%2Fweb%2Fwiklou.git Never prefix table names with $wgSharedDB when used in foreign DB Now database classes have an extra "foreign" property when used in foreign databases, where $wgSharedDB and $wgSharedTables are not considered. Bug: 48819 Change-Id: I45db6860d0a4b4480e0b93aa7e750f096424e40f --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 85c459eef0..8b56ab0ba8 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -236,6 +236,7 @@ abstract class DatabaseBase implements DatabaseType { protected $mTablePrefix; protected $mFlags; + protected $mForeign; protected $mTrxLevel = 0; protected $mErrorCount = 0; protected $mLBInfo = array(); @@ -660,9 +661,10 @@ abstract class DatabaseBase implements DatabaseType { * @param string $dbName database name * @param $flags * @param string $tablePrefix database table prefixes. By default use the prefix gave in LocalSettings.php + * @param bool $foreign disable some operations specific to local databases */ function __construct( $server = false, $user = false, $password = false, $dbName = false, - $flags = 0, $tablePrefix = 'get from global' + $flags = 0, $tablePrefix = 'get from global', $foreign = false ) { global $wgDBprefix, $wgCommandLineMode, $wgDebugDBTransactions; @@ -689,6 +691,8 @@ abstract class DatabaseBase implements DatabaseType { $this->mTablePrefix = $tablePrefix; } + $this->mForeign = $foreign; + if ( $user ) { $this->open( $server, $user, $password, $dbName ); } @@ -738,7 +742,8 @@ abstract class DatabaseBase implements DatabaseType { isset( $p['password'] ) ? $p['password'] : false, isset( $p['dbname'] ) ? $p['dbname'] : false, isset( $p['flags'] ) ? $p['flags'] : 0, - isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global' + isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : 'get from global', + isset( $p['foreign'] ) ? $p['foreign'] : false ); } else { return null; @@ -2068,6 +2073,7 @@ abstract class DatabaseBase implements DatabaseType { } else { list( $table ) = $dbDetails; if ( $wgSharedDB !== null # We have a shared database + && $this->mForeign == false # We're not working on a foreign database && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`' && in_array( $table, $wgSharedTables ) # A shared table is selected ) { diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index f702047885..1d273085fe 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -636,6 +636,7 @@ class LoadBalancer { $server = $this->mServers[$i]; $server['serverIndex'] = $i; $server['foreignPoolRefCount'] = 0; + $server['foreign'] = true; $conn = $this->reallyOpenConnection( $server, $dbName ); if ( !$conn->isOpen() ) { wfDebug( __METHOD__ . ": error opening connection for $i/$wiki\n" ); diff --git a/includes/filerepo/ForeignDBRepo.php b/includes/filerepo/ForeignDBRepo.php index ecad618b5a..37c657236d 100644 --- a/includes/filerepo/ForeignDBRepo.php +++ b/includes/filerepo/ForeignDBRepo.php @@ -63,7 +63,8 @@ class ForeignDBRepo extends LocalRepo { 'password' => $this->dbPassword, 'dbname' => $this->dbName, 'flags' => $this->dbFlags, - 'tablePrefix' => $this->tablePrefix + 'tablePrefix' => $this->tablePrefix, + 'foreign' => true, ) ); }